package example.net;

import java.net.InetAddress;

/**
 * Created by lenovo on 2016/11/7 0007.
 * InetAddress 类的 getLocalAddress() 方法获取本机ip地址及主机名
 */
public class GetLocalHost {
    public static void main(String[] args)
            throws Exception {
        InetAddress addr = InetAddress.getLocalHost();
        System.out.println("Local HostAddress:" + addr.getHostAddress());
        String hostname = addr.getHostName();
        System.out.println("Local host name: " + hostname);
    }
}
